package com.lovo.ssc.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.ssc.entity.BuyPlan;

import com.lovo.ssc.mapper.BuyPlanMapper;
import com.lovo.ssc.service.IBuyPlanService;
import com.lovo.sscsys.dto.BuyPlanMQDto;
import com.lovo.sscsys.util.SSCSYSMQUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 采购表 服务实现类
 * </p>
 *
 * @author lovo
 * @since 2022-07-07
 */
@Service
public class BuyPlanServiceImpl extends ServiceImpl<BuyPlanMapper, BuyPlan> implements IBuyPlanService {
    @Autowired
    RabbitTemplate rabbitTemplate;
    @Override
    public void addAutoPlan(BuyPlanMQDto buyPlanMQDto) {
        BuyPlan buyPlan=new BuyPlan();
        BeanUtils.copyProperties(buyPlanMQDto,buyPlan);
        baseMapper.insert(buyPlan);
        buyPlan.setCode("buyPlan"+buyPlan.getBuyId());
        buyPlan.setAuditState("已申报");
        baseMapper.updateById(buyPlan);
        buyPlanMQDto.setCode(buyPlan.getCode());
//      发送mq
        rabbitTemplate.convertAndSend(SSCSYSMQUtil.directExchangeBuyPlan,SSCSYSMQUtil.buyPlanKey,buyPlanMQDto);
    }




}
